package com.example.qx.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.qx.R;
import com.example.qx.database.data;
import com.example.qx.lei.leilianxr;
import com.example.qx.lei.zhangmi;

import java.security.PublicKey;
import java.sql.SQLException;
import java.util.List;

public class xpyyanzhengadapter extends RecyclerView.Adapter<xpyyanzhengadapter.xpyyanzhengHolder> {

private List<leilianxr> list;
private Context context;
private data data;
private zhangmi grxx= zhangmi.getInstance();



    public xpyyanzhengadapter(Context context,List<leilianxr> list){
        this.list=list;
        this.context=context;
    }
    @NonNull
    @Override
    public xpyyanzhengadapter.xpyyanzhengHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_itemyanzheng,parent,false);
        return new xpyyanzhengHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull xpyyanzhengadapter.xpyyanzhengHolder holder, int position) {
        data=new data();
        leilianxr leilianxr =list.get(position);
        holder.textView.setText(leilianxr.getMingzi());
        holder.buttongyi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                holder.sfty.setText("已通过");
                holder.butjujue.setVisibility(View.GONE);
                holder.buttongyi.setVisibility(View.GONE);
                try {
                    data.chulipygx(1,leilianxr.getId(),grxx.getZhang());
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        holder.butjujue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                holder.sfty.setText("拒绝");
                holder.butjujue.setVisibility(View.GONE);
                holder.buttongyi.setVisibility(View.GONE);
                try {
                    data.chulipygx(0,leilianxr.getId(),grxx.getZhang());
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    public static class xpyyanzhengHolder extends RecyclerView.ViewHolder{
        private TextView textView,sfty;
        private Button buttongyi,butjujue;
        public xpyyanzhengHolder(@NonNull View v) {
            super(v);
            textView=v.findViewById(R.id.yanzhengmingzi);
            buttongyi=v.findViewById(R.id.tongyi);
            butjujue=v.findViewById(R.id.jujue);
            sfty=v.findViewById(R.id.yanzheng);
        }
    };


}
